package activity.servlet;

import activity.dao.Actdao;
import activity.entity.Activity;
import activity.utils.JBDCUlit2;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;

@WebServlet("/deleteact")
public class deleteAct extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String inactid=req.getParameter("inactid");
        System.out.println("删除的活动编号:"+inactid);

        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter out = resp.getWriter();

        JBDCUlit2 db=new JBDCUlit2();
        Activity activity=new Activity();
        activity.setActid(inactid);

        Actdao dao=new Actdao();
        Connection conn= db.getConn();

        try {
            if (dao.delAct(conn,activity)){
                out.println(dao.delAct(conn,activity));
                out.println("<h1>志愿项目或者联系人错误，验证失败</h1>");
                resp.setHeader("Refresh", "1;url=delAct.jsp");
            }else {
                out.println(dao.delAct(conn,activity));
                out.println("<h1>删除成功</h1>");
                resp.setHeader("Refresh", "1;url=Actlist.jsp");
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            out.close();
        }

    }
}
